using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class DepartmentsControl
    {
        #region Local Variable
        private DepartmentsDataAccess _objDAO;
        #endregion Local Variable

        #region Method
        public DepartmentsControl()
        {
            _objDAO = new DepartmentsDataAccess();
        }

        public DepartmentsInfo Get(
        String ROLE_ID,
        String DPT_ID,
        ref string sErr)
        {
            return _objDAO.Get(
            ROLE_ID,
            DPT_ID,
            ref sErr);
        }

        public DataTable GetAll(ref string sErr, string ROLE_ID = null)
        {
            return _objDAO.GetAll(ref sErr, ROLE_ID);
        }
        public DataTable GetByPos(
        int pos, ref string sErr)
        {
            return _objDAO.GetByPos(
            pos, ref sErr);
        }
        public int GetCountRecord(
        ref string sErr)
        {
            return _objDAO.GetCountRecord(
            ref sErr);
        }

        public Int32 Add(DepartmentsInfo obj, ref string sErr)
        {
            return _objDAO.Add(obj, ref sErr);
        }

        public string Update(DepartmentsInfo obj)
        {
            return _objDAO.Update(obj);
        }

        public string Delete(String ROLE_ID, String DPT_ID = null)
        {
            return _objDAO.Delete(ROLE_ID, DPT_ID);
        }
        public Boolean IsExist(
        String ROLE_ID,
        String DPT_ID
        )
        {
            return _objDAO.IsExist(
            ROLE_ID,
            DPT_ID
            );
        }
        
        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _objDAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }
        public string InsertUpdate(DepartmentsInfo obj)
        {
            string sErr = "";
            if (IsExist(
            obj.ROLE_ID,
            obj.DPT_ID
            ))
            {
                sErr = Update(obj);
            }
            else
                Add(obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            return DepartmentsInfo.ToDataTable();
        }

        public string TransferIn(DataRow row)
        {
            DepartmentsInfo inf = new DepartmentsInfo(row);
            return InsertUpdate(inf);
        }
        #endregion Method


        public DataTable getListInSub(string busId, ref string sErr, string connectString = null)
        {
            if (busId == "HL") return _objDAO.getListInSub("TST", ref sErr, connectString);
            return _objDAO.getListInSub("HVJ", ref sErr, connectString);
        }

        
    }
}
